package com.jie.langlangmall.controller;

import com.jie.langlangmall.common.api.CommonPage;
import com.jie.langlangmall.common.api.CommonResult;
import com.jie.langlangmall.dto.SmsFlashPromotionProduct;
import com.jie.langlangmall.model.SmsFlashPromotionProductRelation;
import com.jie.langlangmall.service.SmsFlashPromotionProductRelationService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author Jie
 * @Date 2024/11/26
 * @Email 3217998214@qq.com
 * @Description 限时购和商品关系管理
 */
@RestController
@Tag(name = "SmsFlashPromotionProductRelationController", description = "限时购和商品关系管理")
@RequestMapping("/flashProductRelation")
public class SmsFlashPromotionProductRelationController {

    @Autowired
    private SmsFlashPromotionProductRelationService relationService;

    @Operation(summary = "批量选择商品添加关联")
    @PostMapping("/create")
    public CommonResult<?> create(@RequestBody List<SmsFlashPromotionProductRelation> relationList) {
        relationService.create(relationList);
        return CommonResult.success();
    }

    @Operation(summary = "修改关联信息")
    @PostMapping("/update/{id}")
    public CommonResult<?> update(@PathVariable Long id, @RequestBody SmsFlashPromotionProductRelation relation) {
        relationService.update(id, relation);
        return CommonResult.success();
    }

    @Operation(summary = "删除关联")
    @PostMapping("/delete/{id}")
    public CommonResult<?> delete(@PathVariable("id") Long id) {
        relationService.delete(id);
        return CommonResult.success();
    }

    @Operation(summary = "获取关联商品促销信息")
    @GetMapping("/{id}")
    public CommonResult<SmsFlashPromotionProductRelation> getItem(@PathVariable Long id) {
        SmsFlashPromotionProductRelation relation = relationService.getItem(id);
        return CommonResult.success(relation);
    }

    @Operation(summary = "分页查询")
    @GetMapping("/list")
    public CommonResult<CommonPage<SmsFlashPromotionProduct>> list(@RequestParam(value = "flashPromotionId") Long flashPromotionId,
                                                                   @RequestParam(value = "flashPromotionSessionId") Long flashPromotionSessionId,
                                                                   @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
                                                                   @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
        List<SmsFlashPromotionProduct> flashPromotionProductList = relationService.list(flashPromotionId, flashPromotionSessionId, pageSize, pageNum);
        return CommonResult.success(CommonPage.restPage(flashPromotionProductList));
    }

}
